package com.terren.webdig.common.entity;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

public class LoginSessionContext {
	private static LoginSessionContext instance;
	private Map<String, HttpSession> session_map; // 在线用户列表

	private LoginSessionContext() {
		session_map = new HashMap<String, HttpSession>();
	}

	public static LoginSessionContext getInstance() {
		if (instance == null) {
			instance = new LoginSessionContext();
		}
		return instance;
	}

	public synchronized void AddSession(HttpSession session) {
		if (session != null) {
			session_map.put(session.getId(), session);
		}
	}

	public synchronized void DelSession(HttpSession session) {
		if (session != null) {
			session_map.remove(session.getId());
		}
	}

	public synchronized HttpSession getSession(String session_id) {
		if (session_id == null)
			return null;
		return (HttpSession) session_map.get(session_id);
	}

	public Map<String, HttpSession> getSessionList() {
		return session_map;
	}

	public synchronized int getCurrentLoginCount() {
		return session_map.size();
	}

}
